package core.rdd.transform;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;

import java.util.Arrays;
import java.util.List;

public class Spark07_DISTINCT {

    public static void main(String[] args) {
        /**
         *flatMap 是将多集合转换成一个
         */
        // 配置SparkConf指向你的Spark master URL
        SparkConf conf = new SparkConf()
                .setAppName("Spark07_DISTINCT") // 应用名称
                .setMaster("local[*]"); // 替换成你的master地址
        JavaSparkContext sc = new JavaSparkContext(conf);
        // 创建JavaSparkContext，它是与集群交互的主要入口点
        try {
            List<Integer> integers = Arrays.asList(1, 1, 2, 3, 4, 5, 6);
            JavaRDD<Integer> parallelize = sc.parallelize(integers, 3);

            JavaRDD<Integer> distinct = parallelize.distinct(1);

            distinct.collect().forEach(System.out::println);

        } finally {
            sc.close();
        }
    }
}